package com.sunday.scoremanager.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.sunday.common.widgets.CircleImageView;
import com.sunday.common.widgets.swipe.SwipeMenuAdapter;
import com.sunday.scoremanager.R;
import com.sunday.scoremanager.entity.BankAccount;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by 刘涛 on 2017/11/7.
 */

public class BankAccountlistAdapter extends SwipeMenuAdapter {

    private Context mContext;
    private List<BankAccount> dataSet;
    private LayoutInflater layoutInflater;
    private View.OnClickListener onClickListener;

    public BankAccountlistAdapter(Context context, List<BankAccount> datas) {
        this.mContext = context;
        this.dataSet = datas;
        this.layoutInflater = LayoutInflater.from(mContext);

    }


    @Override
    public View onCreateContentView(ViewGroup parent, int viewType) {
        return layoutInflater.inflate(R.layout.list_bank_account_item, parent, false);
    }

    @Override
    public RecyclerView.ViewHolder onCompatCreateViewHolder(View realContentView, int viewType) {
        return new ListHolder(realContentView);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ListHolder listHolder = (ListHolder) holder;
        BankAccount item = dataSet.get(position);
        Glide.with(mContext)
                .load(item.getLogo())
                .into(listHolder.bankLogo);
        listHolder.bankName.setText(item.getBankName());
        listHolder.bankAccount.setText(item.getBankInfo());
        listHolder.rlBank.setTag(item);
        listHolder.rlBank.setOnClickListener(onClickListener);
    }

    @Override
    public int getItemCount() {
        return dataSet.size();
    }

    public void setOnClickListener(View.OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    class ListHolder extends RecyclerView.ViewHolder {

        @Bind(R.id.bank_logo)
        CircleImageView bankLogo;
        @Bind(R.id.bank_name)
        TextView bankName;
        @Bind(R.id.bank_account)
        TextView bankAccount;
        @Bind(R.id.rl_bank)
        RelativeLayout rlBank;

        public ListHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
